/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package assignment_cp3120.manager.createairport;

import assignment_cp3120.DAO.Factory.DAOFactory;
import assignment_cp3120.dataObjects.DepartureLocation;
import assignment_cp3120.dataObjects.Destination;
import java.util.Vector;

/**
 *
 * @author Administrator
 */
public class CreateAirportModel {
    private Vector<DepartureLocation> airports;

    public CreateAirportModel() {
        loadAirports();
    }
    public void loadAirports() {
        airports = DAOFactory.getDAOFactory().getDepartureLocationDAO().getDepLocations();
    }

    public Vector<DepartureLocation> getAirports() {
        return airports;
    }

    public void setAirports(Vector<DepartureLocation> airports) {
        this.airports = airports;
    }
    public void createAirport(String id, String name, int airportTax){
        boolean perfomEdit = true;

        for (DepartureLocation tempAirport : airports) {
            if (tempAirport.getDep_id().equals(id)) {
                perfomEdit = false;
                System.out.println("Airport exists.");
            }
        }
        if (id.isEmpty()) {
            perfomEdit = false;
            System.out.println("no code given");
        }
        if (perfomEdit) {
            DepartureLocation dep = new DepartureLocation();
            Destination dest = new Destination();
            dep.setDep_id(id);
            dep.setDep_name(name);
            dep.setAirport_tax(airportTax);
            DAOFactory.getDAOFactory().getDepartureLocationDAO().createAirport(dep);

            dest.setDest_id(id);
            dest.setDest_name(name);
            DAOFactory.getDAOFactory().getDestinationDAO().createDestination(dest);

            loadAirports();
        }
    }
}